package fts.ftsmonitoring;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import fts.ftsmonitoring.ftsTaggers.IAutoTagger;
import fts.ftsdata.domain.ITag;
import fts.ftsdata.domain.ITaggedFile;
import fts.ftsdata.services.ITaggingService;


public class Utils
{
	public static void applyTaggersMap(String fileName, ITaggingService taggingService, HashMap<Class<?>, IAutoTagger> taggers)
	{
		Iterator<Class<?>> iter = taggers.keySet().iterator();
		while (iter.hasNext())
		{
			IAutoTagger tagger = taggers.get(iter.next());
			ArrayList<String> tags = tagger.getTags(fileName);
			if (tags != null && !tags.equals(""))
			{
				ITaggedFile file = null;
				try
				{
					file = taggingService.createTaggedFile(fileName);
				}
				catch (Exception e1)
				{
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				if (file != null)
				{
					file.setIsAutoTagged(true);
					for (String tag : tags)
					{
						try
						{
							ITag tagObj = taggingService.createTag(tag);
							file.addAutoTag(tagObj);
						}
						catch (Exception e)
						{

						}
					}
					taggingService.saveTaggedFile(file);
				}
			}
		}
	}
}
